const readFileRes = require("../utils/readFileRes");
// https://www.cnblogs.com/shawn-xie/archive/2013/06/06/3121173.html
const mine = require("../utils/checkExt").types;
let chooseFile = {
  HtmlJsCss(req, res) {
    let rawPath = req.url;
    let suffix = req.url.split(".")[1];
    if (suffix == "js") {
      suffix = "javascript";
    }
    // var contentType = mine[ext] || "text/plain";
    readFileRes.reader(`./src${rawPath}`, res, "utf-8", {
      "content-type": `text/${suffix};charset=utf-8;`,
    });
  },
  Image(req, res) {
    let rawPath = req.url;
    let suffix = req.url.split(".")[1];
    readFileRes.reader(`./src${rawPath}`, res, "", {
      "content-type": `image/${suffix};`,
    });
  },
  fonts(req, res) {
    let rawPath = req.url;
    let suffix = req.url.split(".")[1];
    readFileRes.reader(`./src${rawPath}`, res, "", {
      "content-type": `"application/font-woff/${suffix};`,
    });
  },
};

module.exports = chooseFile;
